package com.slz3.business.module.goodsManagement.gooBaseGoodsAttributeValue.service;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.steward.PageableSteward;
import com.slz3.business.module.goodsManagement.gooBaseGoodsAttributeValue.domain.GooBaseGoodsAttributeValue;
import com.slz3.business.module.goodsManagement.gooBaseGoodsAttributeValue.domain.GooBaseGoodsAttributeValueFactory;
import com.slz3.business.module.goodsManagement.gooBaseGoodsAttributeValue.steward.GooBaseGoodsAttributeValueSpecification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

import java.util.*;

@Slf4j
@Service
public class GooBaseGoodsAttributeValueServiceImpl implements GooBaseGoodsAttributeValueService {
    @Override
    public GooBaseGoodsAttributeValue save(GooBaseGoodsAttributeValue gooBaseGoodsAttributeValue) {
        return Repositorys.gooBaseGoodsAttributeValue.save(GooBaseGoodsAttributeValueFactory.initBaseFields(gooBaseGoodsAttributeValue));
    }
    @Override
    public Page<GooBaseGoodsAttributeValue> page(MultiValueMap<String, String> params) {
        Page<GooBaseGoodsAttributeValue> gooBaseGoodsAttributeValuePage = Repositorys.gooBaseGoodsAttributeValue.findAll(
                GooBaseGoodsAttributeValueSpecification.findJoin(params), PageableSteward.extract(params)
        );
        return gooBaseGoodsAttributeValuePage;
    }


    @Override
    public GooBaseGoodsAttributeValue modify(GooBaseGoodsAttributeValue gooBaseGoodsAttributeValueNew) {
        return Repositorys.gooBaseGoodsAttributeValue.saveAndFlush(GooBaseGoodsAttributeValueFactory.initBaseFields(gooBaseGoodsAttributeValueNew));
    }

    @Override
    public Optional<GooBaseGoodsAttributeValue> single(UUID uuid) {
        return Repositorys.gooBaseGoodsAttributeValue.findById(uuid);
    }

    @Override
    public List<GooBaseGoodsAttributeValue> findAllByUuids(Iterable<UUID> uuids) {
        return Repositorys.gooBaseGoodsAttributeValue.findAllById(uuids);
    }

    @Override
    public List<GooBaseGoodsAttributeValue> delete(List<GooBaseGoodsAttributeValue> gooBaseGoodsAttributeValueList) {
        gooBaseGoodsAttributeValueList.stream().forEach(item -> {
            item.setValidFlag(ValidFlag.DEL);
            GooBaseGoodsAttributeValueFactory.initBaseFields(item);
        });
        return Services.gooBaseGoodsAttributeValueTransactional.batchModify(gooBaseGoodsAttributeValueList);
    }

}
